package com.maxjay.system.web.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import com.maxjay.common.exception.ERR;
import com.maxjay.common.exception.GeneException;
import com.maxjay.system.core.interceptor.ViewState;

public class PageContextTag extends BodyTagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public int doStartTag() throws JspException {
		JspWriter out = pageContext.getOut();  
		ViewState viewState = (ViewState)pageContext.getAttribute(ViewState.VIEWSTATE_PROPERTY_NAME);
		if(viewState != null){
			try {
				out.write("<input type='hidden' name='" + ViewState.VIEWSTATE_KEY + "' value='" + viewState.toString() + "'/>");
			} catch (IOException e) {
				e.printStackTrace();
				throw GeneException.getGeneException(ERR.ERROR_ERR_MSG, e);
			}
		}
		return EVAL_BODY_INCLUDE;
	}
	
}
